package com.qf.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lixu
 */
@Controller
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping
    public String index(Model model){
        List<String> list = new ArrayList<>();
        list.add("123");
        list.add("456");
        list.add("789");
        model.addAttribute("name","宝强");
        model.addAttribute("list",list);
        return "html/demo";
    }


    @GetMapping("/redis")
    public String redis(Model model){

        // Jedis:Redis官方的产品
        // redisTemplate:底层仍然是Jedis 被Spring公司封装了
        redisTemplate.opsForValue().set("name","黄渤");

                // elasticSearchTemplate  jdbcTemplate  redisTemplate  xxxxTemplate

        Object name = redisTemplate.opsForValue().get("name");

        model.addAttribute("name",name);
        return "html/demo";
    }
}
